import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL8FKW5QqHoSmrqk98MoCofk4EHewGYX\n'+
'1q1+FjwkfUv8JWlCOMp6it8mzB/NEG43LUKz/0G80OgRdKme8pv7l3UCAwEAAQ=='

const privateKey = 'MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAvwUpblCoehKauqT3\n'+
'wygKh+TgQd7AZhfWrX4WPCR9S/wlaUI4ynqK3ybMH80QbjctQrP/QbzQ6BF0qZ7y\n'+
'm/uXdQIDAQABAkA8HBS4iRsrJtWX7DenKt99efFz6POkbNX6TFYU4Oqo0QlKyv9L\n'+
'YdYGjeIHSQ//y0IumSrBGgMq7A/Zw15A2o71AiEA6uskAU1+511F6Pwv9GT786/G\n'+
'3iwqQByrCSJEh4bMFIcCIQDQKYexEnASFJSM7S4eUmeaUz3ZRRTKWx5jaZ7dezAv\n'+
'IwIhALydHOR63zhOGFJvIOWdqvlGGWrKlQWyvtRvkgwqe3LDAiEAr4EEVafc83GE\n'+
'mZjzVD9X+EaMk93pnH7cjSak+cl+I48CIB6XLpoOvkpf4N85srK3f1CqtojoATVn\n'+
'1RWo1RED32+y'

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}

